/**
 * @author Pro.Linyl
 * @CreateTime 2015年6月5日
 * @company 杭州微聊网络科技有限公司 版权所有
 * 
 */
package http;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import java.util.List;

import util.BaseUtil;
import util.Constrants;

/***
 * 
 * @author Pro.Linyl
 * @CreateTime 2015年6月5日
 * @UpdateAuthor Pro.Linyl
 * @UpdateTime 2015年6月5日
 * @description http求情消息基类
 *
 */
public abstract class HttpBodyBase {
    protected HttpThread mHttpThread;
	/*** http url path */
	protected String url = "";
	/*** url body path */
	protected String action = "";
    /***
     * 入参
     */
    protected JakyHttpParams params;
    /***
     * 请求返回监听
     */
    private IHttpClinetListener mIHttpClinetListener;
    private Context mContext;

    public HttpBodyBase(Context context) {
        mHttpThread = new HttpThread(context);
        params = new JakyHttpParams();
        mContext = context;
    }
    public void setmIHttpClinetListener(IHttpClinetListener mIHttpClinetListener) {
        this.mIHttpClinetListener = mIHttpClinetListener;
    }

    protected Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            Bundle bundle = msg.getData();
                if (mIHttpClinetListener != null)
                    mIHttpClinetListener.httpSuccessListener(bundle);
            return false;
        }
    });

    /***
	 * 初始化URL
	 * @author Pro.Linyl
	 * @CreateTime 2015年6月8日
	 * @UpdateAuthor Pro.Linyl
	 * @UpdateTime	2015年6月8日
	 * @description 初始化URL
	 *
	 */
	private void initUrl() {
        if(action.contains("http")){
            url = action;
        }else{
		url = Constrants.domain + action;}
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
		initUrl();
        params.put("token", BaseUtil.getToken(mContext));

	}

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

	/***
	 * 发起http请求
	 */
	public void doRequest() {
        mHttpThread.doRequest(this);
    };
    public void doRequest(List<String> mpaths)
    {
        mHttpThread.doRequest(HttpBodyBase.this,mpaths);
    }

    public Context getmContext() {
        return mContext;
    }

    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }
}
